package com.zzyl.controller;

import com.aliyun.iot20180120.models.DeleteDeviceRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation("产品列表数据同步")
    public ResponseResult syncProductList(){
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct(){
        return ResponseResult.success(deviceService.allProduct());
    }

    @PostMapping("/RegisterDevice")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.registerDevice(deviceDto);
        return ResponseResult.success();
    }

    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageResponse<DeviceVo>> selectPage(DevicePageQueryDto devicePageQueryDto){
        return ResponseResult.success(deviceService.selectPage(devicePageQueryDto));
    }

    @PostMapping("/QueryDeviceDetail")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody DeviceDto deviceDto){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    public ResponseResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        return deviceService.queryDevicePropertyStatus(request);
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        return deviceService.queryThingModelPublished(request);
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "修改设备备注名称")
    public ResponseResult<Void> batchUpdateDevice(@RequestBody DeviceDto deviceDto) {
        deviceService.updateDevice(deviceDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/DeleteDevice")
    @ApiOperation(value = "删除设备")
    public ResponseResult<Void> deleteDevice(@RequestBody DeleteDeviceRequest request) {
        deviceService.deleteDevice(request);
        return ResponseResult.success();
    }
 }
